﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CDOP.Model;
using CDOP.Utility;

namespace CDOP
{
    public partial class ForgotPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void BtnResetClick(object sender, EventArgs e)
        {
            var _db = new UserDetails();
            UserDetails userDetails;
            if (_db.TryToGetAuthenticationByEmail(txtEmail.Text, out userDetails))
            {
                var user = userDetails.Authentication.FirstOrDefault();
                if (user != null)
                {
                    var resetPasswordBody = new Authentication().CreateResetPasswordBody(user);
                    Helper.SendEmail(txtEmail.Text, "Reset CDOP Password", resetPasswordBody);
                    lblStatus.Text = "Please check you inbox/spam for the reset link.";
                }
                else
                {
                    lblStatus.Text = "The email address was not found in the system";
                }
            }
            else
            {
                lblStatus.Text = "The email address was not found in the system";
            }
        }
    }
}